// demo2
const { EventEmitter } = require('events');

class Person extends EventEmitter {
  constructor(name) {
    super(name)
    this.name = name;
  }
}

const xiaoming = new Person('xiaoming');
const lili = new Person('lili');
const lucy = new Person('lucy');

const persons = [xiaoming, lili, lucy];

persons.forEach(function (person) {
  person.on('speak', function (msg) {
    console.log(person.name + ' said ' + msg)
  })
})

xiaoming.emit('speak', 'my name is xiaoming');
lili.emit('speak', 'today\'s weathear ia good');
lucy.emit('speak', 'I am a good student')